package com.example.swagger.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@SecurityScheme(name = "petstore_auth", type = SecuritySchemeType.OAUTH2, flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "https://petstore3.swagger.io/oauth/authorize", scopes = {
        @OAuthScope(name = "write:pets", description = "modify pets in your account"),
        @OAuthScope(name = "read:pets", description = "read your pets") })))
@Tag(name = "store", description = "the store API")
@RestController
@RequestMapping("/store")
public class StoreController {

    @Operation(summary = "Delete purchase order by ID", description = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", tags = { "store" })
    @ApiResponses(value = { @ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
            @ApiResponse(responseCode = "404", description = "Order not found") })
    @DeleteMapping(value = "/store/order/{orderId}")
    ResponseEntity<Long> deleteOrder(
            @Parameter(description = "ID of the order that needs to be deleted", required = true, schema = @Schema(type = "integer", format = "int64")) @PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderId);
    }

    @Operation(summary = "Returns pet inventories by status", description = "Returns a map of status codes to quantities", security = {
            @SecurityRequirement(name = "api_key") }, tags = { "store" })
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(schema = @Schema(type = "object"))) })
    @GetMapping(value = "/store/inventory", produces = { "application/json" })
    ResponseEntity<Void> getInventory() {
        return ResponseEntity.ok(null);
    }
}

// 参考 springdoc-openapi 官网 https://github.com/springdoc/springdoc-openapi-demos/blob/master/demo-spring-boot-3-webmvc/src/main/java/org/springdoc/demo/app2/api/PetApi.java